package com.wll.store.user.controller;


import com.wll.store.common.result.Result;
import com.wll.store.user.entity.Order;
import com.wll.store.user.service.OrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdx2009
 * @since 2022-09-08
 */
@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/addorder")
    public Result<?> addOrder(@RequestBody Order order){
        boolean result = orderService.addOrder(order);
        if (result){
            return new Result<>().success();
        }else {
            return new Result<>().error();
        }
    }

    @PostMapping("/orderList")
    public Result<?> orderList(){
        List<Order> orders = orderService.orderList();
        if (!Objects.isNull(orders)){
            return new Result<>().success().put(orders);
        }
        return new Result<>().error("订单查询失败");
    }

    /*@GetMapping("/deleteOrder")
    public Result<?> deleteOrder(){
        boolean result = orderService.deleteOrder();
        if (result){
            return new Result<>().success("删除成功");
        }
        return new Result<>().error("订单删除失败");
    }*/

}
